<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="flSubject">
        <el-input v-model="queryParams.flSubject" placeholder="请输入会议标题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item prop="beginTimeCondition">
        <el-date-picker clearable v-model="queryParams.beginTimeCondition" value-format="yyyy-MM-dd"
            placeholder="请选择开始日期"></el-date-picker>
      </el-form-item>
      <el-form-item prop="endTimeCondition">
        <el-date-picker clearable v-model="queryParams.endTimeCondition" value-format="yyyy-MM-dd"
            placeholder="请选择结束日期"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item>
        <el-select class="select-width" v-model="queryParams.lineType" filterable clearable placeholder="请选择类型">
          <el-option v-for="(item, index) in types" :key="index" :label="item.type" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
          @click="handleDeleteALL">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="linesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="会议标题" align="center" prop="flSubject" />
      <el-table-column label="开始时间" align="center" prop="startTime">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template> -->
      </el-table-column>
      <!--<el-table-column label="状态" align="center" prop="status" width="180">
        <template slot-scope="scope">
          <span>{{ checkSiteType(scope.row.status) }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="参会人员" align="center" prop="numPeople" width="180">
      </el-table-column>
      <el-table-column label="操作" width="200" fixed="right" align="right">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-zoom-in" @click="handleUpdate(scope.row)"
            v-hasPermi="['busport:lines:edit']">查看站点</el-button> -->
          <el-button v-if="scope.row.status==0" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">办理</el-button>
          <el-button size="mini" type="text" icon="el-icon-search" @click="handleDetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <my-room-detail :upload="upload"></my-room-detail>
  </div>
</template>

<script>
import { hyapList, hyapUpdate, hyapDelete } from '../../../api/xzgl/hyyd';
import { getInfo } from '@/api/login'
import myRoomDetail from './myRoomDetail.vue';
export default {
  components: {myRoomDetail},
  data() {
    return {
      // 0：草稿 1：处理中 2：结束 8：已归档 9：已注销
      types: [{
        type: '草稿',
        value: '0'
      },{
        type: '处理中',
        value: '1'
      },
      {
        type: '办结',
        value: '2'
      },
      {
        type: '已归档',
        value: '8'
      },
      {
        type: '已注销',
        value: '9'
      }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 路线表格数据
      linesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        flCreatorId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // lineType: [{ required: true, message: '请选择路线类型', trigger: 'change' }],
        // name: [{ required: true, message: '请填写路线名称', trigger: 'blur' }],
      },
      linesListAll: [],
      flag: 0,
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "会议安排申请",
        row: {}
      },
    };
  },
  created() {
    this.UserInfo()
    // this.getList();
    // this.getAllLines();
  },
  methods: {
    UserInfo() {
      getInfo().then(res => {
        this.queryParams.flCreatorId = res.user.userId
        this.getList()
      })
    },
    /** 查询路线列表 */
    getList() {
      this.loading = true;
      hyapList(this.queryParams).then(response => {
        this.linesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    checkSiteType(row) {
      // 0：草稿 1：处理中 2：结束 8：已归档 9：已注销
      // row = row * 1
      switch (row * 1) {
        case 0:
          return "草稿";
        case 1:
          return "处理中";
        case 2:
          return "办结";
        case 8:
          return "已归档";
        case 9:
          return "已注销";
        default:
          return "其他";
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        // lineType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: '',
        id: null
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {

      this.ids = selection.map(item => item.id)
      // console.log('ids',this.ids);
      // console.log('selection',selection);
      
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.flag = 0
      this.open = true;
      this.title = "添加路线";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      let ids = row.id;
      this.$modal.confirm('是否确认办理').then(function () {
        const params = {
          id: ids,
          status: 1
        }
        return hyapUpdate(params);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("办理成功");
      }).catch((e) => {
        console.log('取消办理',e);
       });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.flag) {
            PupdateLines(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.queryParams.id = null
              this.getList();
            });
          } else {
            PaddLines(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      // this.$router.push({ path: '/xzgl/hyyd/myRoomDetail', query: {id: row.id} })
      this.upload.row = row
      this.upload.open = true
    },
    /** 批量删除按钮操作 */
     handleDeleteALL() {
      // const lineCodes = row.id || this.ids;
      console.log(this.ids);
      let ids = this.ids;
      this.$modal.confirm('是否删除所选会议室').then(function () {
        return hyapDelete(ids[0]);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch((e) => {
        console.log('取消删除',e);
       });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/web/bp/bpspecialline/export', {
        ...this.queryParams
      }, `路线信息_${this.parseTime(new Date(), "{y}-{m}-{d}")}.xlsx`)
    },
    //获取所有路线
    getAllLines() {
      PlistLines({ pageNum: 1, pageSize: 1000 }).then((res) => {
        this.linesListAll = res.rows;
      });
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-select,
.el-date-editor--datetime {
  width: 100%;
}
</style>